package com.ty.zls.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.qmuiteam.qmui.layout.QMUILinearLayout;
import com.qmuiteam.qmui.util.QMUIDisplayHelper;
import com.ty.zls.R;
import com.ty.zls.bean.Water;

import java.util.List;

public class RepayAdapter extends RecyclerView.Adapter<RepayAdapter.ViewHolder> {

    private int total;
    private List<Water> datas;
    private Context context;
    private int pageNum = 1;
    private int pageSize = 5;

    public RepayAdapter(List<Water> datas, Context context) {
        super();
        this.datas = datas;
        this.context = context;
    }

    @NonNull
    @Override
    public RepayAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
        QMUILinearLayout root = (QMUILinearLayout) inflater.inflate(R.layout.prepay_item, viewGroup, false);
        root.setRadiusAndShadow(QMUIDisplayHelper.dp2px(context, 15),
                QMUIDisplayHelper.dp2px(context, 14), 0.25f);
        return new ViewHolder(root);
    }

    @Override
    public void onBindViewHolder(@NonNull RepayAdapter.ViewHolder viewHolder, int i) {
        Water water = datas.get(i);
        viewHolder.setPrice(water.getPrice());
        viewHolder.setEndScale(water.getScale());
        viewHolder.setEndTime(water.getEndTime());
        viewHolder.setLastScale(water.getLastScale());
        viewHolder.setLasttime(water.getLastTime());
        viewHolder.setPeanlty(water.getPenalty());
        viewHolder.setStatus(water.getStatus());
    }


    @Override
    public int getItemCount() {
        return datas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        private TextView record_lasttime_tv;
        private TextView record_endtime_tv;
        private TextView record_lastscale_tv;
        private TextView record_endscale_tv;
        private TextView record_price_tv;
        private TextView record_penalty_tv;
        private TextView record_status_tv;


        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            record_lasttime_tv = itemView.findViewById(R.id.record_lasttime_tv);
            record_endtime_tv = itemView.findViewById(R.id.record_endtime_tv);
            record_lastscale_tv = itemView.findViewById(R.id.record_lastscale_tv);
            record_endscale_tv = itemView.findViewById(R.id.record_endscale_tv);
            record_price_tv = itemView.findViewById(R.id.record_price_tv);
            record_penalty_tv = itemView.findViewById(R.id.record_penalty_tv);
            record_status_tv = itemView.findViewById(R.id.record_status_tv);
        }

        public void setLasttime(String lasttime) {
            record_lasttime_tv.setText(lasttime);
        }

        public void setEndTime(String endTime) {
            record_endtime_tv.setText(endTime);
        }

        public void setLastScale(String lastScale) {
            record_lastscale_tv.setText(lastScale);
        }

        public void setEndScale(String endScale) {
            record_endscale_tv.setText(endScale);
        }

        public void setPrice(String price) {
            record_price_tv.setText(price);
        }

        public void setPeanlty(String penalty) {
            record_penalty_tv.setText(penalty);
        }

        public void setStatus(String status){
            if("0".equals(status)){
                record_status_tv.setText("欠费");
            }else if("1".equals(status)){
                record_status_tv.setText("交清");
            }
        }

    }


    public List<Water> getDatas() {
        return datas;
    }

    public void setDatas(List<Water> datas) {
        this.datas = datas;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

}
